package com.miku.blog.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.miku.blog.domain.UserLoginInfo;
import com.miku.blog.domain.vo.AreaVo;
import com.miku.blog.service.UserLoginInfoService;
import com.miku.blog.mapper.UserLoginInfoMapper;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
* @author Miku
* @description 针对表【tb_user_login_info】的数据库操作Service实现
* @createDate 2022-06-02 08:01:26
*/
@Service
public class UserLoginInfoServiceImpl extends ServiceImpl<UserLoginInfoMapper, UserLoginInfo>
    implements UserLoginInfoService{

    @Override
    public UserLoginInfo getUserLoginInfoByUserId(Integer userId){

        LambdaQueryWrapper<UserLoginInfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(UserLoginInfo::getUserId,userId);
        UserLoginInfo userLoginInfo = getOne(queryWrapper);
        return userLoginInfo;
    }


    @Override
    public boolean updateUserLoginInfo(UserLoginInfo loginInfo) {
        loginInfo.setLastLoginTime(new Date());
        return updateById(loginInfo);
    }


    @Override
    public Page<UserLoginInfo> getUserLoginInfoListByLoginType(Integer current, Integer size, Integer loginType) {

        Page<UserLoginInfo> page = new Page<>();
        LambdaQueryWrapper<UserLoginInfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(UserLoginInfo::getLoginType,loginType)
                .orderByDesc(UserLoginInfo::getCreateTime);
        page(page,queryWrapper);
        return page;
    }


    @Override
    public long getUserLoginInfoByUserIdAndLoginType(Integer userId, Integer loginType) {

        LambdaQueryWrapper<UserLoginInfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(UserLoginInfo::getUserId,userId)
                .eq(UserLoginInfo::getLoginType,loginType);

        return count(queryWrapper);
    }


}




